import PageSearch from '@/components/page-search'
import SearchBtn from 'components/common/SearchBtn.vue'
import PageContent from '@/components/page-content'
import { ref } from 'vue'

export function searchHooks(promiseFunc: any) {
  const searchBtnRef = ref<InstanceType<typeof SearchBtn>>()
  const pageFormRef = ref<InstanceType<typeof PageSearch>>()
  const pageContentRef = ref<InstanceType<typeof PageContent>>()
  const handleSearch = async () => {
    const formData = pageFormRef.value?.handleSearch()
    pageContentRef.value?.handleSearch(
      promiseFunc,
      formData,
      searchBtnRef.value?.handleCloseLoading
    )
  }
  const handleRest = async () => {
    pageFormRef.value?.handleRest()
    pageContentRef.value?.handleRest()
    await handleSearch()
  }
  return {
    searchBtnRef,
    pageFormRef,
    pageContentRef,
    handleSearch,
    handleRest
  }
}
